import { HttpMethod } from '@/services/types';
import { request } from '@/api/request';

/**
 * GET /dynamic 分类列表
 * @param params
 * @param options
 */
export async function resCategoryList(
  params: API.QueryCategory,
  options?: { [key: string]: any },
) {
  return request<API.CategoryListStruct[]>('/category', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/**
 * GET /category/:id 分类详情
 * @param id
 * @param options
 */
export async function resCategoryDetail(
  id: number,
  options?: { [key: string]: any },
) {
  return request<R<API.CategoryStruct>>('/category/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/*    admin    */


/**
 * Delete /admin/category/:id 删除分类
 * @param id
 * @param options
 */
export async function resDeleteCategoryAdmin(
  id: number,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/admin/category/' + id, {
    method: HttpMethod.DELETE,
    ...(options || {}),
  });
}

/**
 * POST /admin/category 添加分类
 * @param params
 * @param options
 */
export async function resAddCategoryAdmin(
  params: API.AddCategoryParams,
  options?: { [key: string]: any },
) {
  return request<API.CategoryStruct>('/admin/category', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * PUT /admin/category/:id 修改分类
 * @param id
 * @param params
 * @param options
 */
export async function resChangeCategoryAdmin(
  id: number,
  params: API.AddCategoryParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/admin/category/' + id, {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /admin/category/status/:id 启用和禁用
 * @param id
 * @param options
 */
export async function resStatusCategoryAdmin(
  id: number,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/admin/category/status/' + id, {
    method: HttpMethod.PATCH,
    ...(options || {}),
  });
}
